package com.yc.web.DTO;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import java.util.Set;

/**
 * 用户数据传输对象。
 * 用于在 Controller 和 Service 层之间传递用户数据，避免直接暴露实体类。
 */
@Data
public class MyUserDTO {
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    @NotBlank(message = "userName cannot be empty")
    @Size(min = 3, max = 50, message = "userName must be between 3 and 50 characters")
    private String userName;

//    @NotBlank(message = "userPassword cannot be empty")
    @Size(min = 6, max = 100, message = "userPassword must be at least 6 characters")
    private String userPassword; // 注册时需要，查询时不返回

    private Set<String> roles; // 用户角色，例如 "ADMIN", "CUST"

    private String mobile; // 手机号

    private String email; // 邮箱

    private String avatar; // 头像 URL
    @JsonIgnore
    private MultipartFile avatarFile;  //上传的头像的实际数据

    private Integer gender; // 性别 (0-未知, 1-男, 2-女)

    private Integer userStatus; // 用户状态 (0-禁用, 1-正常)



    public MyUserDTO(){}

    // 用于快速注册
    public MyUserDTO(String username, String password) {
        this.userName = username;
        this.userPassword = password;
    }
    // 用于快速注册,带角色
    public MyUserDTO(String username, String password, Set<String> roles) {
        this.userName = username;
        this.userPassword = password;
        this.roles = roles;
    }
    // 用于带所有的参数注册
    public MyUserDTO(String username, String password, Set<String> roles, String mobile, String email,
                     MultipartFile avatarFile, Integer gender, Integer userStatus) {
        this.userName = username;
        this.userPassword = password;
        this.roles = roles;
        this.mobile = mobile;
        this.email = email;
        this.avatarFile = avatarFile;
        this.gender = gender;
        this.userStatus = userStatus;
    }

    // 用于更新或查询
    public MyUserDTO(Long userId, String username, Set<String> roles) {
        this.userId = userId;
        this.userName = username;
        this.roles = roles;
    }

    //用于根据 userId更新全部数据
    public MyUserDTO(Long userId, String username, String password, Set<String> roles,
                     String mobile, String email, MultipartFile avatarFile, Integer gender, Integer userStatus) {
        this.userId = userId;
        this.userName = username;
        this.userPassword = password;
        this.roles = roles;
        this.mobile = mobile;
        this.email = email;
        this.avatarFile = avatarFile;
        this.gender = gender;
        this.userStatus = userStatus;
    }
}
